package com.exam.user.config;

import com.exam.user.interceptor.LoginHandlerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        /**
         * 1.页面跳转
         */
        registry.addViewController("/subject/getSingle/**").setViewName("subject_edit");
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/index").setViewName("index");

    }
        /**
         * 2.拦截器配置
         */
        @Bean
        public LoginHandlerInterceptor getOne(){

            return new LoginHandlerInterceptor();
        }

         @Override
       public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getOne())
                .addPathPatterns("/**")
                .excludePathPatterns("/static/**","/webjars/**","/","/login","/index.html","/user/login");
    }


        /**
         * 3.跨域处理
         */

}
